package cm.tfd.hospital.ui.activity;

import android.app.ActionBar;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;

import com.tfd.hospital.R;

import java.util.ArrayList;
import java.util.List;

import cm.tfd.hospital.ui.fragment.homeFragment;
import cm.tfd.hospital.ui.fragment.shopFragment;
import cm.tfd.hospital.view.hometab.BarEntity;
import cm.tfd.hospital.view.hometab.BottomTabBar;


public class MainActivity extends BaseActivity implements BottomTabBar.OnSelectListener {
    private BottomTabBar tb ;
    private List<BarEntity> bars ;
    private FragmentManager manager;
    homeFragment homeFragment;
    shopFragment shopFragment;


    @Override
    protected void initView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_main);
        android.support.v7.app.ActionBar actionBar = getSupportActionBar();
        if (actionBar!=null)
            actionBar.hide();
        showLoading();
        manager = getSupportFragmentManager();
        tb = (BottomTabBar) findViewById(R.id.tb);
        tb.setManager(manager);
        tb.setOnSelectListener(this);
        bars = new ArrayList<>();
        bars.add(new BarEntity( getString(R.string.one),R.mipmap.tab_icon_shouye_sel,R.mipmap.tab_icon_shouye_nor2x));
        bars.add(new BarEntity(getString(R.string.two),R.mipmap.tab_icon_shouye_sel,R.mipmap.tab_icon_shouye_nor2x));
        bars.add(new BarEntity(getString(R.string.three),R.mipmap.tab_icon_shouye_sel,R.mipmap.tab_icon_shouye_nor2x));
        bars.add(new BarEntity(getString(R.string.four),R.mipmap.tab_icon_shouye_sel,R.mipmap.tab_icon_shouye_nor2x));
        tb.setBars(bars);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
    }

    @Override
    public void onSelect(int position) {
        switch (position){
            case 0:
                if (homeFragment ==null){
                    homeFragment = new homeFragment();
                }
                tb.switchContent(homeFragment);
                break;
            case 1:
                if (shopFragment ==null){
                    shopFragment = new shopFragment();
                }
                tb.switchContent(shopFragment);
                break;
            case 2:
                    homeFragment = new homeFragment();
                tb.switchContent(homeFragment);
                break;
            case 3:
                    homeFragment = new homeFragment();
                tb.switchContent(homeFragment);
                break;

            default:
                break;
        }
    }
}
